//
//  StatusListViewModel.swift
//  WeiBo_One
//
//  Created by 李炎 on 15/10/27.
//  Copyright © 2015年 蜡笔小炎. All rights reserved.
//

import Foundation

class StatusListViewModel {
    
    // 微博列表数组
    lazy var statusViewModels = [StatusViewModel]()
    
    /// 加载微博数据
    func loadStatus(finished: (isSuccess: Bool) -> ()) {
        
        NetWorkTools.sharedTools.loadStatus { (result, error) -> () in
            
            if error != nil {// error 有值
                finished(isSuccess: false)
                return
            }
            
            guard let array = result?["statuses"] as? [[String: AnyObject]] else {
                finished(isSuccess: false)
                return
            }
            // 拿到 array 微博字典数组
            var arrayM = [StatusViewModel]()
            for dict in array {
                arrayM.append(StatusViewModel(status: Status(dict: dict)))
            }
            
            // 拼接列表
            self.statusViewModels = arrayM + self.statusViewModels
            finished(isSuccess: true)
        }
    }
    
    

}